package com.bw.dao.impl;

import com.bw.dao.UserDao;
import com.bw.pojo.Role;
import com.bw.pojo.User;
import com.bw.pojo.vo.GetUserDetailsVo;
import com.bw.pojo.vo.UserVo;

import java.util.List;

public class UserDaoImpl extends BaseDao implements UserDao {

    @Override
    public User login(String username) {
        //1.定义sql 语句 2.执行sql 3.赋值
        String sql = "select * from t_user where username = ?";
        User user = baseQueryOne(User.class, sql, username);
        return user;
    }

    @Override
    public List<User> getUserList(User user) {
        String sql = "select * from t_user where  deleted = 0 ";
        if(null != user.getUsername() && !user.getUsername().isEmpty()){
            sql += " and  INSTR(username,'"+user.getUsername()+"')";
        }
        if(null != user.getStart() && !user.getStart().isEmpty()){
            sql += " and time >='"+user.getStart()+"'";
        }
        if(null != user.getStart() && !user.getEnd().isEmpty()){
            sql += " and time <='"+user.getEnd()+"'";
        }

        System.out.println(sql);
        List<User> list = baseQueryList(User.class, sql);
        return list;
    }
    //添加
    @Override
    public void addUser(User user) {
        String sql = "INSERT into t_user (username,password,state,deleted,img_url,time) VALUES (?,?,?,?,?,?)";
        baseUpdate(sql,user.getUsername(),user.getPassword(),user.getStart(),user.getDeleted(),user.getImgUrl(),user.getTime());
    }
    //删除
    @Override
    public void delUser(String uids) {
        //不要用？ 不要用 ‘’ ！！！
        String sql = "update t_user set deleted = 1 where uid in ("+uids+")";
        baseUpdate(sql);
    }

    @Override
    public void userAddAll(List<User> list) {

    }

    @Override
    public void userDel(String[] uid) {

    }

    //回显
    @Override
    public User findById(Integer uid) {
        String sql = "select * from t_user where uid = ?";
        User user = baseQueryOne(User.class, sql, uid);
        return user;
    }

    @Override
    public void del(Integer uid) {

    }

    @Override
    public void updUser(User user) {
        String sql = "update t_user set username=?,password=?,time=?,img_url=? where uid = ?";
        baseUpdate(sql ,user.getUsername(),user.getPassword(),user.getTime(),user.getImgUrl(),user.getUid());

    }

    @Override
    public List<GetUserDetailsVo> userList() {
        return null;
    }

    @Override
    public UserVo getUserByUserId(Integer uid) {
        return null;
    }

    @Override
    public List<UserVo> getUserListByMap(UserVo userVo) {
        return null;
    }

    @Override
    public List<Role> getRoleListUser(Integer uid) {
        return null;
    }

}
